<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品分类</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 全部商品表格 -->
      <!-- :selection-type取消前面选框 show-index索引 index-text索引名称 show-row-hover取消鼠标悬停高亮 expand-type是否展开-->
      <tree-table
        :data="cateList"
        :columns="columns"
        :selection-type="false"
        show-index
        index-text="#"
        :show-row-hover="false"
        border
        :expand-type="false"
      >
        <!-- 是否有效 -->
        <template slot="isOk" slot-scope="scope">
          <i class="el-icon-success" v-if="scope.row.cat_deleted===true" style="color: lightgreen"></i>
          <i class="el-icon-erro" v-else style="color: red"></i>
        </template>
        <!-- 排序 -->
        <template slot="sort" slot-scope="scope">
          <el-tag v-if="scope.row.cat_level===0">一级</el-tag>
          <el-tag v-else-if="scope.row.cat_level===1" type="success">二级</el-tag>
          <el-tag v-else type="warning">三级</el-tag>
        </template>
      </tree-table>
      <!-- 分页功能 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="cateinfo.pagenum"
        :page-sizes="[5, 10]"
        :page-size="cateinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
import '@/mock/dfmock'
export default {
  data () {
    return {
      // 获取数据参数
      cateinfo: {
        pagenum: 1,
        pagesize: 5
      },
      // 获取商品分类数据
      cateList: [],
      // 总数据数量
      total: 0,
      // 树形表格列的数据
      columns: [
        {
          label: '分类名称',
          prop: 'cat_name'
        },
        {
          label: '是否有效',
          type: 'template',
          template: 'isOk'
        },
        {
          label: '排序',
          type: 'template',
          template: 'sort'
        }
      ]
    }
  },
  created () {
    this.getCateList()
  },
  methods: {
    // 获取商品分类列表
    async getCateList() {
      const res = await this.axios.get('/order', {
        params: this.cateinfo
      })
      if (res.data.status !== 200) return this.$message.error('获取商品分类失败')
      this.cateList = res.data.data.list
      this.total = res.data.data.total
    },
    // 点击修改每页展示条目数触发
    handleSizeChange(num) {
      this.cateinfo.pagesize = num
      this.getCateList()
    },
    // 点击修改当前页码触发
    handleCurrentChange(num) {
      this.cateinfo.pagenum = num
      this.getCateList()
    }
  }
}
</script>

<style scoped lang="less">
  .el-cascader {
    width: 100%;
  }
</style>
